#include "directoryblock.h"

DirectoryBlock::DirectoryBlock(FILE* device, unsigned long offset) : Block(device, offset)
{
	dirs = new std::vector<Directory*>();
	dirBlock = new directory_block_t();
	read(dirBlock, sizeof(directory_block_t));

	loadDirs();

}

DirectoryBlock::~DirectoryBlock()
{
	for(int i = 0; i < dirs->size(); i++)
	{
		delete (*dirs)[i];
	}

	delete dirs;
	delete dirBlock;
}

void DirectoryBlock::loadDirs()
{
	for(int i = 0; i < DIRLIST_SIZE; i++)
	{
		//cout << "Load Dir at: " << offset + DIR_SIZE * i << endl;
		dirs->push_back(new Directory(device, offset + DIR_SIZE * i));
	}
}

void DirectoryBlock::print()
{
    for(int i = 0; i < dirs->size(); i++)
    {
        (*dirs)[i]->print();
    }
}
